home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: macro that return value, how?
- Date: Fri, 01 Mar 1996 15:23:44 +0200
- Organization: Carelcomp Forest
- Message-ID: <3136FA60.350B@cmt.lpr.mail.carel.fi>
- References: <3133e87b.868433@news.csus.edu>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- Jerry Leong wrote:
- >
- > Hi,
- > I need to define a macro that will first calculate a given a
- > parameter and then return it. How can I do that?
- >
- > p/s: Say I pass a value to the macro, macro will perform some
- > addition, then return the value.
- >
- > #define add1(x) { x+=VAR; return x; }
- >
- > something like that by the above does not compile.
- > Thanx in advance!
-
- This will compile:
-
- #define add1(x) (x += VAR)
-
- Remember, the result of an assignment is implicitly returned. So, you can use
- constructs like:
-
- if ((x += 2) == 2)
- DoSomething...
-
- and
- if (add1(2) == 2)
- DoSomething...
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-